﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Hxsoft.AppV1;
using Hxsoft.AppV1.Module;

namespace Hxsoft.AppV1.Admin.Controls
{
	[ValidationProperty("Value")]
	public partial class Site : DataListSelector<int, List<Hxsoft.AppV1.Module.Site>>
	{
		#region 属性
		protected override Wuqi.Webdiyer.AspNetPager Pager
		{
			get { return pager; }
		}

		protected override DataList DataList
		{
			get { return List; }
		}

		public int[] SiteIds
		{
			get { return (int[])ViewState["SiteIds"]; }
			set { ViewState["SiteIds"] = value; }
		}

		// 列数
		public int RepeatColumns
		{
			get { return List.RepeatColumns; }
			set{ List.RepeatColumns = value; }
		}


		// 页尺寸
		public int PageSize
		{
			get { return pager.PageSize; }
			set { pager.PageSize = value; }
		}
		#endregion


		protected override void Render(HtmlTextWriter writer)
		{
			EventHandler handler = SelectFinishEventHandler;
			if (handler == null)
				LbSelectGroup.Visible = false;

			base.Render(writer);
		}


		#region 函数
		protected override PaginationInfo<List<Hxsoft.AppV1.Module.Site>> GetData()
		{
			return Sites.GetPaginationSelectorList(TbKeyword.Text, SiteIds, pager.PageSize, pager.CurrentPageIndex);
		}

		/// <summary>
		/// 取得 ListItem 的标识符。
		/// </summary>
		/// <param name="item">列表的 ListItem。</param>
		/// <returns>ListItem 的标识符。</returns>
		protected override int GetListItemType(DataListItem item)
		{
			int identifier;
			HiddenField control;

			control = (HiddenField)item.FindControl("Identifier_SiteID");
			identifier = Convert.ToInt32(control.Value);

			return identifier;
		}
		#endregion
	}
}